package finman.database;
import java.util.*;

public class Database {
	
	private User currentUser;
	private Set<User> users;
	
	private Set<Bank> banks;
	private Set<Organization> organizations;
	private Set<Contract> contracts;
	private Set<Valuta> currencies;

	
	public Database(User user)
	throws UserNotFoundException {
		//-------------------- fiiling the database --------------------
		users = new HashSet<User>(3);
		users.add(new User("adfgs", "afgasr", User.Permission.full));
		users.add(new User("abc", "xxx", User.Permission.full));
		users.add(new User("ihnb", "347b", User.Permission.full));
		
		banks = new HashSet<Bank>(3);
		banks.add(new Bank("Privat"));
		banks.add(new Bank("public"));
		banks.add(new Bank("protected"));
		for(Bank bank: banks) {
			bank.openAccount(new Valuta("usd"), -999d);
		}
		//--------------------------------------------------------------
		// trying to find a user
		boolean user_is_exist = false;
		for(User userInBase : users) {
			if((userInBase.getName().equals(user.getName())) &&
			   (userInBase.getPassword().equals(user.getPassword()))) {
			   user_is_exist = true;
			   break;
			}
		}
		if(! user_is_exist)
			throw new UserNotFoundException();
		//------------------------------------------
		// autorization compleated!
		// what next? ...
	}
	
	public String[] getAllAccountsInAllBanks() {
		LinkedList<String> accountList = new LinkedList<String>();
		for(Bank bank: banks) {
			//TODO
		}
		return accountList.toArray(new String[0]);
	}
	
}